package yunhe.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import yunhe.biz.IProcureBiz;
import yunhe.biz.impl.ProcureBizImpl;
import yunhe.entity.PurchaseAppend;
@WebServlet(name="ReturnOperateServlet",urlPatterns="/ReturnOperateServlet")
public class ReturnOperateServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		IProcureBiz ipb=new ProcureBizImpl();
		String excuteState=request.getParameter("flag");
		String purId=request.getParameter("purId");
		PrintWriter out=response.getWriter();
		if("0".equals(excuteState)){
			 boolean flag=ipb.deletePurchaseAndPurchaseAppendBypurId(purId);
			 if(flag){
				 out.print("<script>alert('退货成功')</script>");
			 }else{
				 out.print("<script>alert('退货失败')</script>");
			 }
			 response.sendRedirect("SelectPurchaseAppendByPages");
		}else if("1".equals(excuteState)){
			PurchaseAppend purchaseAppend=ipb.selectPurchaseAppendByPurchaseAppend(purId);
			request.setAttribute("purchaseAppend", purchaseAppend);
			request.getRequestDispatcher("/purchase/returnCreate.jsp").forward(request, response);
		}
		
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}
}
